package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.itheima.dao.MenuDao;
import com.itheima.pojo.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = MenuService.class)
@Transactional
public class MenuServiceImpl implements MenuService{

    @Autowired
    private MenuDao menuDao;

    @Override
    public List<Menu> getMenu(Integer userId) {
        List<Integer> list = menuDao.selectMenuIdByUserId(userId);
        if(list!= null){
            List<Menu> menuList = menuDao.getMenu(list);
            System.out.println(JSON.toJSONString(menuList));
            return menuList;
        }

        return null;
    }

    @Override
    public List<Menu> findAll() {
        return menuDao.findAll();
    }
}
